package com.yuncheng.oaApi.controller;

import java.util.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import com.yuncheng.vo.HttpResult;
import com.yuncheng.common.query.QueryBuilder;
import com.yuncheng.annotation.AutoLog;
import com.yuncheng.utils.I18nUtil;
import com.yuncheng.common.base.controller.BaseController;
import com.yuncheng.oaApi.entity.QyReservationSxlb;
import com.yuncheng.oaApi.service.IQyReservationSxlbService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.yuncheng.system.api.SystemAPI;
import org.springframework.context.annotation.Lazy;

/**
 * @Description: 企业预约咨询事项类别
 * @Author: lhb
 * @Date: 2023-12-22
 * @Version: V1.0
 */
@Api(tags = "企业预约咨询事项类别接口")
@RestController
@RequestMapping("/api/spzx-oa/qyReservationSxlb")
public class QyReservationSxlbController extends BaseController<QyReservationSxlb, IQyReservationSxlbService> {

    private static final Logger log = LoggerFactory.getLogger(QyReservationSxlbController.class);

    @Resource
    private IQyReservationSxlbService qyReservationSxlbService;

    @Resource
    @Lazy
    private SystemAPI systemAPI;

    /**
     * 分页列表查询
     *
     * @param qyReservationSxlb
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @AutoLog(value = "企业预约咨询事项类别-分页列表查询")
    @ApiOperation(value = "企业预约咨询事项类别-分页列表查询")
    @GetMapping(value = "/list")
    public HttpResult<?> queryPageList(QyReservationSxlb qyReservationSxlb, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
        QueryWrapper<QyReservationSxlb> queryWrapper = QueryBuilder.initQueryWrapper(qyReservationSxlb, req.getParameterMap());
        Page<QyReservationSxlb> page = new Page<>(pageNo, pageSize);
        IPage<QyReservationSxlb> pageList = qyReservationSxlbService.page(page, queryWrapper);
        for(QyReservationSxlb vo:pageList.getRecords()){
            formatValue(vo);
        }
        return HttpResult.ok(pageList);
    }





    /**
     * 添加
     *
     * @param qyReservationSxlb
     * @return
     */
    @AutoLog(value = "企业预约咨询事项类别-添加")
    @ApiOperation(value = "企业预约咨询事项类别-添加")
    //@RequiresPermissions("qy2:QyReservationSxlb:add")
    @PostMapping(value = "/add")
    public HttpResult<?> add(@RequestBody QyReservationSxlb qyReservationSxlb) {
        HttpResult<String> result = new HttpResult(true);
        qyReservationSxlbService.save(qyReservationSxlb);
        result.setResult(qyReservationSxlb.getId());
        result.setMessage(I18nUtil.message("save.success"));
        return result;
    }

    /**
     * 编辑
     *
     * @param qyReservationSxlb
     * @return
     */
    @AutoLog(value = "企业预约咨询事项类别-编辑")
    @ApiOperation(value = "企业预约咨询事项类别-编辑")
    //@RequiresPermissions("qy2:QyReservationSxlb:edit")
    @PutMapping(value = "/edit")
    public HttpResult<?> edit(@RequestBody QyReservationSxlb qyReservationSxlb) {
        qyReservationSxlbService.updateById(qyReservationSxlb);
        return HttpResult.ok(I18nUtil.message("update.success"));
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "企业预约咨询事项类别-通过id删除")
    @ApiOperation(value = "企业预约咨询事项类别-通过id删除")
    //@RequiresPermissions("qy2:QyReservationSxlb:delete")
    @DeleteMapping(value = "/delete")
    public HttpResult<?> delete(@RequestParam("id") String id) {
        qyReservationSxlbService.removeById(id);
        return HttpResult.ok(I18nUtil.message("delete.success"));
    }

    /**
     * 通过id批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "企业预约咨询事项类别-批量删除")
    @ApiOperation(value = "企业预约咨询事项类别-批量删除")
    //@RequiresPermissions("qy2:QyReservationSxlb:delete")
    @DeleteMapping(value = "/deleteBatch")
    public HttpResult<?> deleteBatch(@RequestParam("ids") String ids) {
        qyReservationSxlbService.removeByIds(Arrays.asList(ids.split(",")));
        return HttpResult.ok(I18nUtil.message("delete.success"));
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @AutoLog(value = "企业预约咨询事项类别-通过id查询")
    @ApiOperation(value = "企业预约咨询事项类别-通过id查询")
    @GetMapping(value = "/queryById")
    public HttpResult<?> queryById(@RequestParam("id") String id) {
        QyReservationSxlb qyReservationSxlb = qyReservationSxlbService.getById(id);
        return HttpResult.ok(qyReservationSxlb);
    }


    /**
     * 数据转换
     * @param qyReservationSxlb
     */
    private void formatValue(QyReservationSxlb qyReservationSxlb){
    }
}
